package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     * @param dto
     * @return
     */
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO dto){
        return shoppingCartService.add(dto);
    }

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("/list")
    public Result list (){
        return shoppingCartService.list();
    }

    /**
     * 删除购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result clean(){
        return shoppingCartService.clean();
    }

    /**
     * 商品减一
     * @param dto
     * @return
     */
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO dto){
        return shoppingCartService.sub(dto);

    }
}
